-
Notifications
You must be signed in to change notification settings - Fork 328
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[api] return an error when the specified height is not supported #4174
Conversation
Quality Gate failedFailed conditions |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #4174 +/- ##
==========================================
- Coverage 76.51% 76.41% -0.10%
==========================================
Files 340 340
Lines 29273 28997 -276
==========================================
- Hits 22397 22159 -238
+ Misses 5761 5731 -30
+ Partials 1115 1107 -8 ☔ View full report in Codecov by Sentry. |
api/web3server.go
Outdated
@@ -311,11 +312,36 @@ func (svr *web3Handler) getBlockByNumber(in *gjson.Result) (interface{}, error) | |||
return svr.getBlockWithTransactions(blk.Block, blk.Receipts, isDetailed.Bool()) | |||
} | |||
|
|||
func (svr *web3Handler) checkInputBlockNumber(str string) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
according to the eth standards, this str
could be either a block number, a block enum, or a block hash. The implementation here may be incomplete
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and prefer name it as checkInputBlock
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://ethereum.org/en/developers/docs/apis/json-rpc/#default-block
When requests are made that act on the state of Ethereum, the last default block parameter determines the height of the block.
The following options are possible for the defaultBlock parameter:
HEX String - an integer block number
String "earliest" for the earliest/genesis block
String "latest" - for the latest mined block
String "safe" - for the latest safe head block
String "finalized" - for the latest finalized block
String "pending" - for the pending state/transactions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That content may lack complete details. Refer to the following for specifics:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This fix should be released with archive mode features, because this fix will cause graph-node fail without archive mode. |
Quality Gate failedFailed conditions |
case "", _earliestBlockNumber, _pendingBlockNumber: | ||
return errInvalidBlockHeight | ||
case _latestBlockNumber: | ||
return nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
delete
case _latestBlockNumber: | ||
return nil | ||
default: | ||
//check str is block hash string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tip := svr.coreService.TipHeight()
@@ -322,11 +323,46 @@ func (svr *web3Handler) getBlockByNumber(in *gjson.Result) (interface{}, error) | |||
return svr.getBlockWithTransactions(blk.Block, blk.Receipts, isDetailed.Bool()) | |||
} | |||
|
|||
func (svr *web3Handler) checkInputBlock(str string) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
func (svr *web3Handler) checkHeight(input gjson.Result) error {
if !input.Exists() {
return nil
}
Description
Currently we do not support archive mode. When querying these web3APIs
if a height is specified, the result is returned for the latest height. This PR fixes returning an error if height is not supported
Fixes #4167
Type of change
Please delete options that are not relevant.
How Has This Been Tested?
Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration
Test Configuration:
Checklist: